package liquibase.util.grammar;

import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class SimpleSqlGrammar implements SimpleSqlGrammarConstants {
    public SimpleSqlGrammarTokenManager token_source;

    SimpleCharStream jj_input_stream;

    public Token token;

    public Token jj_nt;

    private int jj_ntk;

    private int jj_gen;

    private final int[] jj_la1 = new int[0];

    private static int[] jj_la1_0;

    private List<int[]> jj_expentries;

    private int[] jj_expentry;

    private int jj_kind;

    private boolean trace_enabled;

    static {
        jj_la1_init_0();
    }

    private static void jj_la1_init_0() {
        jj_la1_0 = new int[0];
    }

    public SimpleSqlGrammar(InputStream stream) {
        this(stream, null);
    }

    public void ReInit(InputStream stream) {
        ReInit(stream, null);
    }

    public void ReInit(InputStream stream, String encoding) {
        try {
            this.jj_input_stream.ReInit(stream, encoding, 1, 1);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        this.token_source.ReInit(this.jj_input_stream);
        this.token = new Token();
        this.jj_ntk = -1;
        this.jj_gen = 0;
        for (int i = 0; i < 0; ) {
            this.jj_la1[i] = -1;
            i++;
        }
    }

    public void ReInit(Reader stream) {
        if (this.jj_input_stream == null) {
            this.jj_input_stream = new SimpleCharStream(stream, 1, 1);
        } else {
            this.jj_input_stream.ReInit(stream, 1, 1);
        }
        if (this.token_source == null)
            this.token_source = new SimpleSqlGrammarTokenManager(this.jj_input_stream);
        this.token_source.ReInit(this.jj_input_stream);
        this.token = new Token();
        this.jj_ntk = -1;
        this.jj_gen = 0;
    }

    public void ReInit(SimpleSqlGrammarTokenManager tm) {
        this.token_source = tm;
        this.token = new Token();
        this.jj_ntk = -1;
        this.jj_gen = 0;
    }

    private Token jj_consume_token(int kind) throws ParseException {
        Token oldToken;
        if ((oldToken = this.token).next != null) {
            this.token = this.token.next;
        } else {
            this.token = this.token.next = this.token_source.getNextToken();
        }
        this.jj_ntk = -1;
        if (this.token.kind == kind) {
            this.jj_gen++;
            return this.token;
        }
        this.token = oldToken;
        this.jj_kind = kind;
        throw generateParseException();
    }

    public final Token getNextToken() {
        if (this.token.next != null) {
            this.token = this.token.next;
        } else {
            this.token = this.token.next = this.token_source.getNextToken();
        }
        this.jj_ntk = -1;
        this.jj_gen++;
        return this.token;
    }

    public final Token getToken(int index) {
        Token t = this.token;
        for (int i = 0; i < index; i++) {
            if (t.next != null) {
                t = t.next;
            } else {
                t = t.next = this.token_source.getNextToken();
            }
        }
        return t;
    }

    private int jj_ntk_f() {
        if ((this.jj_nt = this.token.next) == null)
            return this.jj_ntk = (this.token.next = this.token_source.getNextToken()).kind;
        return this.jj_ntk = this.jj_nt.kind;
    }

    public SimpleSqlGrammar(InputStream stream, String encoding) {
        this.jj_expentries = (List)new ArrayList<>();
        this.jj_kind = -1;
        try {
            this.jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        this.token_source = new SimpleSqlGrammarTokenManager(this.jj_input_stream);
        this.token = new Token();
        this.jj_ntk = -1;
        this.jj_gen = 0;
    }

    public SimpleSqlGrammar(Reader stream) {
        this.jj_expentries = (List)new ArrayList<>();
        this.jj_kind = -1;
        this.jj_input_stream = new SimpleCharStream(stream, 1, 1);
        this.token_source = new SimpleSqlGrammarTokenManager(this.jj_input_stream);
        this.token = new Token();
        this.jj_ntk = -1;
        this.jj_gen = 0;
    }

    public SimpleSqlGrammar(SimpleSqlGrammarTokenManager tm) {
        this.jj_expentries = (List)new ArrayList<>();
        this.jj_kind = -1;
        this.token_source = tm;
        this.token = new Token();
        this.jj_ntk = -1;
        this.jj_gen = 0;
    }

    public ParseException generateParseException() {
        this.jj_expentries.clear();
        boolean[] la1tokens = new boolean[21];
        if (this.jj_kind >= 0) {
            la1tokens[this.jj_kind] = true;
            this.jj_kind = -1;
        }
        int i;
        for (i = 0; i < 0; i++) {
            if (this.jj_la1[i] == this.jj_gen)
                for (int k = 0; k < 32; k++) {
                    if ((jj_la1_0[i] & 1 << k) != 0)
                        la1tokens[k] = true;
                }
        }
        for (i = 0; i < 21; i++) {
            if (la1tokens[i]) {
                this.jj_expentry = new int[1];
                this.jj_expentry[0] = i;
                this.jj_expentries.add(this.jj_expentry);
            }
        }
        int[][] exptokseq = new int[this.jj_expentries.size()][];
        for (int j = 0; j < this.jj_expentries.size(); j++)
            exptokseq[j] = this.jj_expentries.get(j);
        return new ParseException(this.token, exptokseq, tokenImage);
    }

    public final boolean trace_enabled() {
        return this.trace_enabled;
    }

    public final void enable_tracing() {}

    public final void disable_tracing() {}
}
